package com.lin.controller;

import com.lin.common.error.CustomRuntimeException;
import com.lin.common.rest.ResMsg;
import com.lin.controller.req.AddLifeReqMsg;
import com.lin.controller.req.RangeReqMsg;
import com.lin.service.ranges.RangesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Api(tags = "附近范围入口")
@RestController
@RequestMapping("/msvc")
public class RangesController {

    @Autowired
    private RangesService rangesService;

    @ApiOperation("新增生活接口，10分钟调用一次,用户获得实时定位信息")
    @PostMapping("/location")
    public ResMsg<Integer> location(@Valid @RequestBody RangeReqMsg reqMsg) throws CustomRuntimeException {
        ResMsg<Integer> urs = new ResMsg<>();
        Integer i = rangesService.location(reqMsg);
        return urs.withData(i);
    }

    @ApiOperation("设置随遇的开关")
    @PostMapping("/encounter-flag")
    public ResMsg<Integer> encounterFlag(@Valid @RequestBody RangeReqMsg reqMsg) throws CustomRuntimeException {
        //TODO 未实现，用于设置encounter的开关；在websocket connection中，如果flag为true，则连接，否则close；
        return null;
//        ResMsg<Integer> urs = new ResMsg<>();
//        Integer i = rangesService.location(reqMsg);
//        return urs.withData(i);
    }

}
